package com.cjh.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cjh.annotation.WebLog;
import com.cjh.feign.MenuFeign;
import com.cjh.feign.UserFeign;
import com.cjh.pojo.Menu;
import com.cjh.pojo.Type;
import com.cjh.pojo.User;
import com.cjh.vo.ResultMap;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
@RestController
@RequestMapping("/userApi")
public class UserController {

    @Autowired
    private UserFeign userFeign;

    @GetMapping("/userList")
    @WebLog(description = "请求=>查询所有用户信息接口")
    public ResultMap userList(@RequestParam(value = "page", defaultValue = "1") Integer page
            , @RequestParam(value = "limit", defaultValue = "10") Integer limit) {
        PageInfo<User> userPageInfo = userFeign.userList(page, limit);

        return new ResultMap<List<User>>(0, "所有用户信息->每页10条数据", userPageInfo.getList(), (int) userPageInfo.getTotal());
    }

    @PostMapping("/insertUser")
    @WebLog(description = "请求=>添加用户接口")
    public ResultMap insertUser(User user){
        boolean flag = userFeign.insertUser(user);
        return new ResultMap<String>(200,"添加一个用户","SUCCESS",1);
    }

    @DeleteMapping("/deleteUserById/{id}")
    @WebLog(description = "请求=>删除用户接口")
    public ResultMap deleteUserById(@PathVariable("id") Integer id){
        boolean flag = userFeign.deleteUserById(id);
        return new ResultMap<String>(200,"根据id删除一个用户","删除成功",1);
    }

    @PutMapping("/updateUserById")
    @WebLog(description = "请求=>修改用户接口")
    public ResultMap updateUserById(User user){
        System.out.println("====消费者====："+user);
        boolean flag = userFeign.updateUserById(user);
        return new ResultMap<String>(200,"修改一个用户","修改成功",1);
    }

}
